//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

use proto_gen_rust::config_api::config_api_client::ConfigApiClient;
use proto_gen_rust::config_api::*;
use tauri::{AppHandle, Runtime};

#[tauri::command]
pub async fn config_api_cmds_get_server_config<R: Runtime>(
    app_handle: AppHandle<R>,
    request: GetServerConfigRequest,
) -> Result<GetServerConfigResponse, String> {
    let chan = super::get_grpc_chan(&app_handle).await;
    if (&chan).is_none() {
        return Err("no grpc conn".into());
    }
    let mut client = ConfigApiClient::new(chan.unwrap());
    match client.get_server_config(request).await {
        Ok(response) => {
            let inner_resp = response.into_inner();
            return Ok(inner_resp);
        }
        Err(status) => Err(status.message().into()),
    }
}
